<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class BasicSocket - socket: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">IO
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-do_not_reverse_lookup">::do_not_reverse_lookup</a>
    <li ><a href="#method-c-do_not_reverse_lookup-3D">::do_not_reverse_lookup=</a>
    <li ><a href="#method-c-for_fd">::for_fd</a>
    <li ><a href="#method-i-close_read">#close_read</a>
    <li ><a href="#method-i-close_write">#close_write</a>
    <li ><a href="#method-i-connect_address">#connect_address</a>
    <li ><a href="#method-i-do_not_reverse_lookup">#do_not_reverse_lookup</a>
    <li ><a href="#method-i-do_not_reverse_lookup-3D">#do_not_reverse_lookup=</a>
    <li ><a href="#method-i-getpeereid">#getpeereid</a>
    <li ><a href="#method-i-getpeername">#getpeername</a>
    <li ><a href="#method-i-getsockname">#getsockname</a>
    <li ><a href="#method-i-getsockopt">#getsockopt</a>
    <li ><a href="#method-i-local_address">#local_address</a>
    <li ><a href="#method-i-recv">#recv</a>
    <li ><a href="#method-i-recv_nonblock">#recv_nonblock</a>
    <li ><a href="#method-i-recvmsg">#recvmsg</a>
    <li ><a href="#method-i-recvmsg_nonblock">#recvmsg_nonblock</a>
    <li ><a href="#method-i-remote_address">#remote_address</a>
    <li ><a href="#method-i-send">#send</a>
    <li ><a href="#method-i-sendmsg">#sendmsg</a>
    <li ><a href="#method-i-sendmsg_nonblock">#sendmsg_nonblock</a>
    <li ><a href="#method-i-setsockopt">#setsockopt</a>
    <li ><a href="#method-i-shutdown">#shutdown</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-BasicSocket">
    <h1 id="class-BasicSocket" class="class">
      class BasicSocket
    </h1>

    <section class="description">
    
<p><a href="BasicSocket.html"><code>BasicSocket</code></a> is the super class for all the <a href="Socket.html"><code>Socket</code></a> classes.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-do_not_reverse_lookup" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          do_not_reverse_lookup &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Gets the global <a href="BasicSocket.html#method-c-do_not_reverse_lookup"><code>do_not_reverse_lookup</code></a> flag.</p>

<pre class="ruby"><span class="ruby-constant">BasicSocket</span>.<span class="ruby-identifier">do_not_reverse_lookup</span>  <span class="ruby-comment">#=&gt; false</span>
</pre>

                              <div class="method-source-code" id="do_not_reverse_lookup-source">
            <pre>static VALUE
bsock_do_not_rev_lookup(VALUE _)
{
    return rsock_do_not_reverse_lookup?Qtrue:Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-do_not_reverse_lookup-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          do_not_reverse_lookup = bool
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the global <a href="BasicSocket.html#method-c-do_not_reverse_lookup"><code>do_not_reverse_lookup</code></a> flag.</p>

<p>The flag is used for initial value of <a href="BasicSocket.html#method-c-do_not_reverse_lookup"><code>do_not_reverse_lookup</code></a> for each socket.</p>

<pre class="ruby"><span class="ruby-identifier">s1</span> = <span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;localhost&quot;</span>, <span class="ruby-value">80</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">do_not_reverse_lookup</span>                 <span class="ruby-comment">#=&gt; true</span>
<span class="ruby-constant">BasicSocket</span>.<span class="ruby-identifier">do_not_reverse_lookup</span> = <span class="ruby-keyword">false</span>
<span class="ruby-identifier">s2</span> = <span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;localhost&quot;</span>, <span class="ruby-value">80</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">do_not_reverse_lookup</span>                 <span class="ruby-comment">#=&gt; false</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">do_not_reverse_lookup</span>                 <span class="ruby-comment">#=&gt; true</span>
</pre>

                              <div class="method-source-code" id="do_not_reverse_lookup-3D-source">
            <pre>static VALUE
bsock_do_not_rev_lookup_set(VALUE self, VALUE val)
{
    rsock_do_not_reverse_lookup = RTEST(val);
    return val;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-for_fd" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          for_fd(fd) &rarr; basicsocket
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a socket object which contains the file descriptor, <em>fd</em>.</p>

<pre class="ruby"><span class="ruby-comment"># If invoked by inetd, STDIN/STDOUT/STDERR is a socket.</span>
<span class="ruby-constant">STDIN_SOCK</span> = <span class="ruby-constant">Socket</span>.<span class="ruby-identifier">for_fd</span>(<span class="ruby-constant">STDIN</span>.<span class="ruby-identifier">fileno</span>)
<span class="ruby-identifier">p</span> <span class="ruby-constant">STDIN_SOCK</span>.<span class="ruby-identifier">remote_address</span>
</pre>

                              <div class="method-source-code" id="for_fd-source">
            <pre>static VALUE
bsock_s_for_fd(VALUE klass, VALUE _descriptor)
{
    rb_io_t *fptr;

    int descriptor = RB_NUM2INT(_descriptor);
    rsock_validate_descriptor(descriptor);

    VALUE sock = rsock_init_sock(rb_obj_alloc(klass), descriptor);

    GetOpenFile(sock, fptr);

    return sock;
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-close_read" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          close_read &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Disallows further read using shutdown system call.</p>

<pre class="ruby"><span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span> = <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">pair</span>
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">close_read</span>
<span class="ruby-identifier">s2</span>.<span class="ruby-identifier">puts</span> <span class="ruby-comment">#=&gt; Broken pipe (Errno::EPIPE)</span>
</pre>

                              <div class="method-source-code" id="close_read-source">
            <pre>static VALUE
bsock_close_read(VALUE sock)
{
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    shutdown(fptr-&gt;fd, 0);
    if (!(fptr-&gt;mode &amp; FMODE_WRITABLE)) {
        return rb_io_close(sock);
    }
    fptr-&gt;mode &amp;= ~FMODE_READABLE;

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-close_write" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          close_write &rarr; nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Disallows further write using shutdown system call.</p>

<pre class="ruby"><span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">pair</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">&quot;ping&quot;</span>
  <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">close_write</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">read</span>        <span class="ruby-comment">#=&gt; &quot;ping&quot;</span>
  <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">print</span> <span class="ruby-string">&quot;pong&quot;</span>
  <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">close</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">read</span>        <span class="ruby-comment">#=&gt; &quot;pong&quot;</span>
}
</pre>

                              <div class="method-source-code" id="close_write-source">
            <pre>static VALUE
bsock_close_write(VALUE sock)
{
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    if (!(fptr-&gt;mode &amp; FMODE_READABLE)) {
        return rb_io_close(sock);
    }
    shutdown(fptr-&gt;fd, 1);
    fptr-&gt;mode &amp;= ~FMODE_WRITABLE;

    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-connect_address" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">connect_address</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an address of the socket suitable for connect in the local machine.</p>

<p>This method returns <em>self</em>.local_address, except following condition.</p>
<ul><li>
<p>IPv4 unspecified address (0.0.0.0) is replaced by IPv4 loopback address (127.0.0.1).</p>
</li><li>
<p>IPv6 unspecified address (::) is replaced by IPv6 loopback address (::1).</p>
</li></ul>

<p>If the local address is not suitable for connect, <a href="SocketError.html"><code>SocketError</code></a> is raised. IPv4 and IPv6 address which port is 0 is not suitable for connect. Unix domain socket which has no path is not suitable for connect.</p>

<pre class="ruby"><span class="ruby-constant">Addrinfo</span>.<span class="ruby-identifier">tcp</span>(<span class="ruby-string">&quot;0.0.0.0&quot;</span>, <span class="ruby-value">0</span>).<span class="ruby-identifier">listen</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">serv</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">connect_address</span> <span class="ruby-comment">#=&gt; #&lt;Addrinfo: 127.0.0.1:53660 TCP&gt;</span>
  <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">connect_address</span>.<span class="ruby-identifier">connect</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">s</span>, <span class="ruby-identifier">_</span> = <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">accept</span>
    <span class="ruby-identifier">p</span> [<span class="ruby-identifier">c</span>, <span class="ruby-identifier">s</span>] <span class="ruby-comment">#=&gt; [#&lt;Socket:fd 4&gt;, #&lt;Socket:fd 6&gt;]</span>
  }
}
</pre>

                              <div class="method-source-code" id="connect_address-source">
            <pre><span class="ruby-comment"># File socket/lib/socket.rb, line 255</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">connect_address</span>
  <span class="ruby-identifier">addr</span> = <span class="ruby-identifier">local_address</span>
  <span class="ruby-identifier">afamily</span> = <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">afamily</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">afamily</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">AF_INET</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">SocketError</span>, <span class="ruby-string">&quot;unbound IPv4 socket&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_port</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_address</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;0.0.0.0&quot;</span>
      <span class="ruby-identifier">addr</span> = <span class="ruby-constant">Addrinfo</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&quot;AF_INET&quot;</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_port</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&quot;127.0.0.1&quot;</span>], <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">pfamily</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">socktype</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">protocol</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">AF_INET6</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">afamily</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">AF_INET6</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">SocketError</span>, <span class="ruby-string">&quot;unbound IPv6 socket&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_port</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_address</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;::&quot;</span>
      <span class="ruby-identifier">addr</span> = <span class="ruby-constant">Addrinfo</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&quot;AF_INET6&quot;</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_port</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&quot;::1&quot;</span>], <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">pfamily</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">socktype</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">protocol</span>)
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_address</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;0.0.0.0&quot;</span> <span class="ruby-comment"># MacOS X 10.4 returns &quot;a.b.c.d&quot; for IPv4-mapped IPv6 address.</span>
      <span class="ruby-identifier">addr</span> = <span class="ruby-constant">Addrinfo</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&quot;AF_INET6&quot;</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_port</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&quot;::1&quot;</span>], <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">pfamily</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">socktype</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">protocol</span>)
    <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_address</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;::ffff:0.0.0.0&quot;</span> <span class="ruby-comment"># MacOS X 10.6 returns &quot;::ffff:a.b.c.d&quot; for IPv4-mapped IPv6 address.</span>
      <span class="ruby-identifier">addr</span> = <span class="ruby-constant">Addrinfo</span>.<span class="ruby-identifier">new</span>([<span class="ruby-string">&quot;AF_INET6&quot;</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">ip_port</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-string">&quot;::1&quot;</span>], <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">pfamily</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">socktype</span>, <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">protocol</span>)
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">AF_UNIX</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">afamily</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">AF_UNIX</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">SocketError</span>, <span class="ruby-string">&quot;unbound Unix socket&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">addr</span>.<span class="ruby-identifier">unix_path</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">addr</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-do_not_reverse_lookup" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          do_not_reverse_lookup &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Gets the <a href="BasicSocket.html#method-c-do_not_reverse_lookup"><code>do_not_reverse_lookup</code></a> flag of <em>basicsocket</em>.</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;socket&#39;</span>

<span class="ruby-constant">BasicSocket</span>.<span class="ruby-identifier">do_not_reverse_lookup</span> = <span class="ruby-keyword">false</span>
<span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;www.ruby-lang.org&quot;</span>, <span class="ruby-value">80</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">sock</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">do_not_reverse_lookup</span>      <span class="ruby-comment">#=&gt; false</span>
}
<span class="ruby-constant">BasicSocket</span>.<span class="ruby-identifier">do_not_reverse_lookup</span> = <span class="ruby-keyword">true</span>
<span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;www.ruby-lang.org&quot;</span>, <span class="ruby-value">80</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">sock</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">do_not_reverse_lookup</span>      <span class="ruby-comment">#=&gt; true</span>
}
</pre>

                              <div class="method-source-code" id="do_not_reverse_lookup-source">
            <pre>static VALUE
bsock_do_not_reverse_lookup(VALUE sock)
{
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    return (fptr-&gt;mode &amp; FMODE_NOREVLOOKUP) ? Qtrue : Qfalse;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-do_not_reverse_lookup-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          do_not_reverse_lookup = bool
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the <a href="BasicSocket.html#method-c-do_not_reverse_lookup"><code>do_not_reverse_lookup</code></a> flag of <em>basicsocket</em>.</p>

<pre class="ruby"><span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;www.ruby-lang.org&quot;</span>, <span class="ruby-value">80</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">sock</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">do_not_reverse_lookup</span>       <span class="ruby-comment">#=&gt; true</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">peeraddr</span>                    <span class="ruby-comment">#=&gt; [&quot;AF_INET&quot;, 80, &quot;221.186.184.68&quot;, &quot;221.186.184.68&quot;]</span>
  <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">do_not_reverse_lookup</span> = <span class="ruby-keyword">false</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">peeraddr</span>                    <span class="ruby-comment">#=&gt; [&quot;AF_INET&quot;, 80, &quot;carbon.ruby-lang.org&quot;, &quot;54.163.249.195&quot;]</span>
}
</pre>

                              <div class="method-source-code" id="do_not_reverse_lookup-3D-source">
            <pre>static VALUE
bsock_do_not_reverse_lookup_set(VALUE sock, VALUE state)
{
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    if (RTEST(state)) {
        fptr-&gt;mode |= FMODE_NOREVLOOKUP;
    }
    else {
        fptr-&gt;mode &amp;= ~FMODE_NOREVLOOKUP;
    }
    return sock;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-getpeereid" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          getpeereid &rarr; [euid, egid]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the user and group on the peer of the UNIX socket. The result is a two element array which contains the effective uid and the effective gid.</p>

<pre class="ruby"><span class="ruby-constant">Socket</span>.<span class="ruby-identifier">unix_server_loop</span>(<span class="ruby-string">&quot;/tmp/sock&quot;</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">euid</span>, <span class="ruby-identifier">egid</span> = <span class="ruby-identifier">s</span>.<span class="ruby-identifier">getpeereid</span>

    <span class="ruby-comment"># Check the connected client is myself or not.</span>
    <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">euid</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">uid</span>

    <span class="ruby-comment"># do something about my resource.</span>

  <span class="ruby-keyword">ensure</span>
    <span class="ruby-identifier">s</span>.<span class="ruby-identifier">close</span>
  <span class="ruby-keyword">end</span>
}
</pre>

                              <div class="method-source-code" id="getpeereid-source">
            <pre>static VALUE
bsock_getpeereid(VALUE self)
{
#if defined(HAVE_GETPEEREID)
    rb_io_t *fptr;
    uid_t euid;
    gid_t egid;
    GetOpenFile(self, fptr);
    if (getpeereid(fptr-&gt;fd, &amp;euid, &amp;egid) == -1)
        rb_sys_fail(&quot;getpeereid(3)&quot;);
    return rb_assoc_new(UIDT2NUM(euid), GIDT2NUM(egid));
#elif defined(SO_PEERCRED) /* GNU/Linux */
    rb_io_t *fptr;
    struct ucred cred;
    socklen_t len = sizeof(cred);
    GetOpenFile(self, fptr);
    if (getsockopt(fptr-&gt;fd, SOL_SOCKET, SO_PEERCRED, &amp;cred, &amp;len) == -1)
        rb_sys_fail(&quot;getsockopt(SO_PEERCRED)&quot;);
    return rb_assoc_new(UIDT2NUM(cred.uid), GIDT2NUM(cred.gid));
#elif defined(HAVE_GETPEERUCRED) /* Solaris */
    rb_io_t *fptr;
    ucred_t *uc = NULL;
    VALUE ret;
    GetOpenFile(self, fptr);
    if (getpeerucred(fptr-&gt;fd, &amp;uc) == -1)
        rb_sys_fail(&quot;getpeerucred(3C)&quot;);
    ret = rb_assoc_new(UIDT2NUM(ucred_geteuid(uc)), GIDT2NUM(ucred_getegid(uc)));
    ucred_free(uc);
    return ret;
#endif
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-getpeername" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          getpeername &rarr; sockaddr
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the remote address of the socket as a sockaddr string.</p>

<pre class="ruby"><span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;127.0.0.1&quot;</span>, <span class="ruby-value">1440</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">serv</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">c</span> = <span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;127.0.0.1&quot;</span>, <span class="ruby-value">1440</span>)
  <span class="ruby-identifier">s</span> = <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">accept</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">getpeername</span> <span class="ruby-comment">#=&gt; &quot;\x02\x00\x82u\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00&quot;</span>
}
</pre>

<p>If <a href="Addrinfo.html"><code>Addrinfo</code></a> object is preferred over the binary string, use <a href="BasicSocket.html#method-i-remote_address"><code>BasicSocket#remote_address</code></a>.</p>

                              <div class="method-source-code" id="getpeername-source">
            <pre>static VALUE
bsock_getpeername(VALUE sock)
{
    union_sockaddr buf;
    socklen_t len = (socklen_t)sizeof buf;
    socklen_t len0 = len;
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    if (getpeername(fptr-&gt;fd, &amp;buf.addr, &amp;len) &lt; 0)
        rb_sys_fail(&quot;getpeername(2)&quot;);
    if (len0 &lt; len) len = len0;
    return rb_str_new((char*)&amp;buf, len);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-getsockname" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          getsockname &rarr; sockaddr
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the local address of the socket as a sockaddr string.</p>

<pre class="ruby"><span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;127.0.0.1&quot;</span>, <span class="ruby-value">15120</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">serv</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">getsockname</span> <span class="ruby-comment">#=&gt; &quot;\x02\x00;\x10\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00&quot;</span>
}
</pre>

<p>If <a href="Addrinfo.html"><code>Addrinfo</code></a> object is preferred over the binary string, use <a href="BasicSocket.html#method-i-local_address"><code>BasicSocket#local_address</code></a>.</p>

                              <div class="method-source-code" id="getsockname-source">
            <pre>static VALUE
bsock_getsockname(VALUE sock)
{
    union_sockaddr buf;
    socklen_t len = (socklen_t)sizeof buf;
    socklen_t len0 = len;
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    if (getsockname(fptr-&gt;fd, &amp;buf.addr, &amp;len) &lt; 0)
        rb_sys_fail(&quot;getsockname(2)&quot;);
    if (len0 &lt; len) len = len0;
    return rb_str_new((char*)&amp;buf, len);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-getsockopt" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          getsockopt(level, optname) &rarr; socketoption
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Gets a socket option. These are protocol and system specific, see your local system documentation for details. The option is returned as a <a href="Socket/Option.html"><code>Socket::Option</code></a> object.</p>

<h3 id="method-i-getsockopt-label-Parameters">Parameters<span><a href="#method-i-getsockopt-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><code>level</code> is an integer, usually one of the SOL_ constants such as Socket::SOL_SOCKET, or a protocol level. A string or symbol of the name, possibly without prefix, is also accepted.</p>
</li><li>
<p><code>optname</code> is an integer, usually one of the SO_ constants, such as Socket::SO_REUSEADDR. A string or symbol of the name, possibly without prefix, is also accepted.</p>
</li></ul>

<h3 id="method-i-getsockopt-label-Examples">Examples<span><a href="#method-i-getsockopt-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Some socket options are integers with boolean values, in this case <a href="BasicSocket.html#method-i-getsockopt"><code>getsockopt</code></a> could be called like this:</p>

<pre class="ruby"><span class="ruby-identifier">reuseaddr</span> = <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">getsockopt</span>(<span class="ruby-value">:SOCKET</span>, <span class="ruby-value">:REUSEADDR</span>).<span class="ruby-identifier">bool</span>

<span class="ruby-identifier">optval</span> = <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">getsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">SOL_SOCKET</span>,<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">SO_REUSEADDR</span>)
<span class="ruby-identifier">optval</span> = <span class="ruby-identifier">optval</span>.<span class="ruby-identifier">unpack</span> <span class="ruby-string">&quot;i&quot;</span>
<span class="ruby-identifier">reuseaddr</span> = <span class="ruby-identifier">optval</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">false</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>
</pre>

<p>Some socket options are integers with numeric values, in this case <a href="BasicSocket.html#method-i-getsockopt"><code>getsockopt</code></a> could be called like this:</p>

<pre class="ruby"><span class="ruby-identifier">ipttl</span> = <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">getsockopt</span>(<span class="ruby-value">:IP</span>, <span class="ruby-value">:TTL</span>).<span class="ruby-identifier">int</span>

<span class="ruby-identifier">optval</span> = <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">getsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">IPPROTO_IP</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">IP_TTL</span>)
<span class="ruby-identifier">ipttl</span> = <span class="ruby-identifier">optval</span>.<span class="ruby-identifier">unpack1</span>(<span class="ruby-string">&quot;i&quot;</span>)
</pre>

<p>Option values may be structs. Decoding them can be complex as it involves examining your system headers to determine the correct definition. An example is a +struct linger+, which may be defined in your system headers as:</p>

<pre class="ruby"><span class="ruby-identifier">struct</span> <span class="ruby-identifier">linger</span> {
  <span class="ruby-identifier">int</span> <span class="ruby-identifier">l_onoff</span>;
  <span class="ruby-identifier">int</span> <span class="ruby-identifier">l_linger</span>;
};
</pre>

<p>In this case <a href="BasicSocket.html#method-i-getsockopt"><code>getsockopt</code></a> could be called like this:</p>

<pre class="ruby"><span class="ruby-comment"># Socket::Option knows linger structure.</span>
<span class="ruby-identifier">onoff</span>, <span class="ruby-identifier">linger</span> = <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">getsockopt</span>(<span class="ruby-value">:SOCKET</span>, <span class="ruby-value">:LINGER</span>).<span class="ruby-identifier">linger</span>

<span class="ruby-identifier">optval</span> =  <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">getsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">SOL_SOCKET</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">SO_LINGER</span>)
<span class="ruby-identifier">onoff</span>, <span class="ruby-identifier">linger</span> = <span class="ruby-identifier">optval</span>.<span class="ruby-identifier">unpack</span> <span class="ruby-string">&quot;ii&quot;</span>
<span class="ruby-identifier">onoff</span> = <span class="ruby-identifier">onoff</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-operator">?</span> <span class="ruby-keyword">false</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">true</span>
</pre>

                              <div class="method-source-code" id="getsockopt-source">
            <pre>static VALUE
bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
{
    int level, option;
    socklen_t len;
    char *buf;
    rb_io_t *fptr;
    int family;

    GetOpenFile(sock, fptr);
    family = rsock_getfamily(fptr);
    level = rsock_level_arg(family, lev);
    option = rsock_optname_arg(family, level, optname);
    len = 256;
#ifdef _AIX
    switch (option) {
      case SO_DEBUG:
      case SO_REUSEADDR:
      case SO_KEEPALIVE:
      case SO_DONTROUTE:
      case SO_BROADCAST:
      case SO_OOBINLINE:
        /* AIX doesn&#39;t set len for boolean options */
        len = sizeof(int);
    }
#endif
    buf = ALLOCA_N(char,len);

    rb_io_check_closed(fptr);

    if (getsockopt(fptr-&gt;fd, level, option, buf, &amp;len) &lt; 0)
        rsock_sys_fail_path(&quot;getsockopt(2)&quot;, fptr-&gt;pathv);

    return rsock_sockopt_new(family, level, option, rb_str_new(buf, len));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-local_address" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          local_address &rarr; addrinfo
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an <a href="Addrinfo.html"><code>Addrinfo</code></a> object for local address obtained by getsockname.</p>

<p>Note that addrinfo.protocol is filled by 0.</p>

<pre class="ruby"><span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;www.ruby-lang.org&quot;</span>, <span class="ruby-value">80</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">local_address</span> <span class="ruby-comment">#=&gt; #&lt;Addrinfo: 192.168.0.129:36873 TCP&gt;</span>
}

<span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;127.0.0.1&quot;</span>, <span class="ruby-value">1512</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">serv</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">local_address</span> <span class="ruby-comment">#=&gt; #&lt;Addrinfo: 127.0.0.1:1512 TCP&gt;</span>
}
</pre>

                              <div class="method-source-code" id="local_address-source">
            <pre>static VALUE
bsock_local_address(VALUE sock)
{
    union_sockaddr buf;
    socklen_t len = (socklen_t)sizeof buf;
    socklen_t len0 = len;
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    if (getsockname(fptr-&gt;fd, &amp;buf.addr, &amp;len) &lt; 0)
        rb_sys_fail(&quot;getsockname(2)&quot;);
    if (len0 &lt; len) len = len0;
    return rsock_fd_socket_addrinfo(fptr-&gt;fd, &amp;buf.addr, len);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-recv" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          recv(maxlen[, flags[, outbuf]]) &rarr; mesg
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Receives a message.</p>

<p><em>maxlen</em> is the maximum number of bytes to receive.</p>

<p><em>flags</em> should be a bitwise OR of Socket::MSG_* constants.</p>

<p><em>outbuf</em> will contain only the received data after the method call even if it is not empty at the beginning.</p>

<pre class="ruby"><span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">pair</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">s1</span>, <span class="ruby-identifier">s2</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;Hello World&quot;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">recv</span>(<span class="ruby-value">4</span>)                     <span class="ruby-comment">#=&gt; &quot;Hell&quot;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">recv</span>(<span class="ruby-value">4</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">MSG_PEEK</span>)   <span class="ruby-comment">#=&gt; &quot;o Wo&quot;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">recv</span>(<span class="ruby-value">4</span>)                     <span class="ruby-comment">#=&gt; &quot;o Wo&quot;</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">recv</span>(<span class="ruby-value">10</span>)                    <span class="ruby-comment">#=&gt; &quot;rld\n&quot;</span>
}
</pre>

                              <div class="method-source-code" id="recv-source">
            <pre>static VALUE
bsock_recv(int argc, VALUE *argv, VALUE sock)
{
    return rsock_s_recvfrom(sock, argc, argv, RECV_RECV);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-recv_nonblock" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          recv_nonblock(maxlen [, flags [, buf [, options ]]]) &rarr; mesg
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Receives up to <em>maxlen</em> bytes from <code>socket</code> using recvfrom(2) after O_NONBLOCK is set for the underlying file descriptor. <em>flags</em> is zero or more of the <code>MSG_</code> options. The result, <em>mesg</em>, is the data received.</p>

<p>When recvfrom(2) returns 0, <a href="BasicSocket.html#method-i-recv_nonblock"><code>Socket#recv_nonblock</code></a> returns an empty string as data. The meaning depends on the socket: EOF on TCP, empty packet on UDP, etc.</p>

<h3 id="method-i-recv_nonblock-label-Parameters">Parameters<span><a href="#method-i-recv_nonblock-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><code>maxlen</code> - the number of bytes to receive from the socket</p>
</li><li>
<p><code>flags</code> - zero or more of the <code>MSG_</code> options</p>
</li><li>
<p><code>buf</code> - destination String buffer</p>
</li><li>
<p><code>options</code> - keyword hash, supporting ‘exception: false`</p>
</li></ul>

<h3 id="method-i-recv_nonblock-label-Example">Example<span><a href="#method-i-recv_nonblock-label-Example">&para;</a> <a href="#top">&uarr;</a></span></h3>

<pre class="ruby"><span class="ruby-identifier">serv</span> = <span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;127.0.0.1&quot;</span>, <span class="ruby-value">0</span>)
<span class="ruby-identifier">af</span>, <span class="ruby-identifier">port</span>, <span class="ruby-identifier">host</span>, <span class="ruby-identifier">addr</span> = <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">addr</span>
<span class="ruby-identifier">c</span> = <span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">addr</span>, <span class="ruby-identifier">port</span>)
<span class="ruby-identifier">s</span> = <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">accept</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">send</span> <span class="ruby-string">&quot;aaa&quot;</span>, <span class="ruby-value">0</span>
<span class="ruby-keyword">begin</span> <span class="ruby-comment"># emulate blocking recv.</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">recv_nonblock</span>(<span class="ruby-value">10</span>) <span class="ruby-comment">#=&gt; &quot;aaa&quot;</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">IO</span><span class="ruby-operator">::</span><span class="ruby-constant">WaitReadable</span>
  <span class="ruby-constant">IO</span>.<span class="ruby-identifier">select</span>([<span class="ruby-identifier">s</span>])
  <span class="ruby-keyword">retry</span>
<span class="ruby-keyword">end</span>
</pre>

<p>Refer to <a href="Socket.html#method-i-recvfrom"><code>Socket#recvfrom</code></a> for the exceptions that may be thrown if the call to <em>recv_nonblock</em> fails.</p>

<p><a href="BasicSocket.html#method-i-recv_nonblock"><code>BasicSocket#recv_nonblock</code></a> may raise any error corresponding to recvfrom(2) failure, including Errno::EWOULDBLOCK.</p>

<p>If the exception is Errno::EWOULDBLOCK or Errno::EAGAIN, it is extended by IO::WaitReadable. So IO::WaitReadable can be used to rescue the exceptions for retrying recv_nonblock.</p>

<p>By specifying a keyword argument <em>exception</em> to <code>false</code>, you can indicate that <a href="BasicSocket.html#method-i-recv_nonblock"><code>recv_nonblock</code></a> should not raise an IO::WaitReadable exception, but return the symbol <code>:wait_readable</code> instead.</p>

<h3 id="method-i-recv_nonblock-label-See">See<span><a href="#method-i-recv_nonblock-label-See">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Socket.html#method-i-recvfrom"><code>Socket#recvfrom</code></a></p>
</li></ul>

                              <div class="method-source-code" id="recv_nonblock-source">
            <pre><span class="ruby-comment"># File socket/lib/socket.rb, line 375</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">recv_nonblock</span>(<span class="ruby-identifier">len</span>, <span class="ruby-identifier">flag</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">str</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-value">exception:</span> <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">__recv_nonblock</span>(<span class="ruby-identifier">len</span>, <span class="ruby-identifier">flag</span>, <span class="ruby-identifier">str</span>, <span class="ruby-identifier">exception</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-recvmsg" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          recvmsg(maxmesglen=nil, flags=0, maxcontrollen=nil, opts={}) &rarr; [mesg, sender_addrinfo, rflags, *controls]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>recvmsg receives a message using recvmsg(2) system call in blocking manner.</p>

<p><em>maxmesglen</em> is the maximum length of mesg to receive.</p>

<p><em>flags</em> is bitwise OR of MSG_* constants such as Socket::MSG_PEEK.</p>

<p><em>maxcontrollen</em> is the maximum length of controls (ancillary data) to receive.</p>

<p><em>opts</em> is option hash. Currently :scm_rights=&gt;bool is the only option.</p>

<p>:scm_rights option specifies that application expects SCM_RIGHTS control message. If the value is nil or false, application don’t expects SCM_RIGHTS control message. In this case, recvmsg closes the passed file descriptors immediately. This is the default behavior.</p>

<p>If :scm_rights value is neither nil nor false, application expects SCM_RIGHTS control message. In this case, recvmsg creates IO objects for each file descriptors for <a href="Socket/AncillaryData.html#method-i-unix_rights"><code>Socket::AncillaryData#unix_rights</code></a> method.</p>

<p>The return value is 4-elements array.</p>

<p><em>mesg</em> is a string of the received message.</p>

<p><em>sender_addrinfo</em> is a sender socket address for connection-less socket. It is an <a href="Addrinfo.html"><code>Addrinfo</code></a> object. For connection-oriented socket such as TCP, sender_addrinfo is platform dependent.</p>

<p><em>rflags</em> is a flags on the received message which is bitwise OR of MSG_* constants such as Socket::MSG_TRUNC. It will be nil if the system uses 4.3BSD style old recvmsg system call.</p>

<p><em>controls</em> is ancillary data which is an array of <a href="Socket/AncillaryData.html"><code>Socket::AncillaryData</code></a> objects such as:</p>

<pre class="ruby"><span class="ruby-comment">#&lt;Socket::AncillaryData: AF_UNIX SOCKET RIGHTS 7&gt;</span>
</pre>

<p><em>maxmesglen</em> and <em>maxcontrollen</em> can be nil. In that case, the buffer will be grown until the message is not truncated. Internally, MSG_PEEK is used. Buffer full and MSG_CTRUNC are checked for truncation.</p>

<p>recvmsg can be used to implement recv_io as follows:</p>

<pre class="ruby"><span class="ruby-identifier">mesg</span>, <span class="ruby-identifier">sender_sockaddr</span>, <span class="ruby-identifier">rflags</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">controls</span> = <span class="ruby-identifier">sock</span>.<span class="ruby-identifier">recvmsg</span>(<span class="ruby-value">:scm_rights</span><span class="ruby-operator">=&gt;</span><span class="ruby-keyword">true</span>)
<span class="ruby-identifier">controls</span>.<span class="ruby-identifier">each</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">ancdata</span><span class="ruby-operator">|</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">ancdata</span>.<span class="ruby-identifier">cmsg_is?</span>(<span class="ruby-value">:SOCKET</span>, <span class="ruby-value">:RIGHTS</span>)
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">ancdata</span>.<span class="ruby-identifier">unix_rights</span>[<span class="ruby-value">0</span>]
  <span class="ruby-keyword">end</span>
}
</pre>

                              <div class="method-source-code" id="recvmsg-source">
            <pre><span class="ruby-comment"># File socket/lib/socket.rb, line 430</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">recvmsg</span>(<span class="ruby-identifier">dlen</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">flags</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">clen</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-value">scm_rights:</span> <span class="ruby-keyword">false</span>)
  <span class="ruby-identifier">__recvmsg</span>(<span class="ruby-identifier">dlen</span>, <span class="ruby-identifier">flags</span>, <span class="ruby-identifier">clen</span>, <span class="ruby-identifier">scm_rights</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-recvmsg_nonblock" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          recvmsg_nonblock(maxdatalen=nil, flags=0, maxcontrollen=nil, opts={}) &rarr; [data, sender_addrinfo, rflags, *controls]
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>recvmsg receives a message using recvmsg(2) system call in non-blocking manner.</p>

<p>It is similar to <a href="BasicSocket.html#method-i-recvmsg"><code>BasicSocket#recvmsg</code></a> but non-blocking flag is set before the system call and it doesn’t retry the system call.</p>

<p>By specifying a keyword argument <em>exception</em> to <code>false</code>, you can indicate that <a href="BasicSocket.html#method-i-recvmsg_nonblock"><code>recvmsg_nonblock</code></a> should not raise an IO::WaitReadable exception, but return the symbol <code>:wait_readable</code> instead.</p>

                              <div class="method-source-code" id="recvmsg_nonblock-source">
            <pre><span class="ruby-comment"># File socket/lib/socket.rb, line 446</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">recvmsg_nonblock</span>(<span class="ruby-identifier">dlen</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">flags</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">clen</span> = <span class="ruby-keyword">nil</span>,
                     <span class="ruby-value">scm_rights:</span> <span class="ruby-keyword">false</span>, <span class="ruby-value">exception:</span> <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">__recvmsg_nonblock</span>(<span class="ruby-identifier">dlen</span>, <span class="ruby-identifier">flags</span>, <span class="ruby-identifier">clen</span>, <span class="ruby-identifier">scm_rights</span>, <span class="ruby-identifier">exception</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-remote_address" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          remote_address &rarr; addrinfo
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an <a href="Addrinfo.html"><code>Addrinfo</code></a> object for remote address obtained by getpeername.</p>

<p>Note that addrinfo.protocol is filled by 0.</p>

<pre class="ruby"><span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;www.ruby-lang.org&quot;</span>, <span class="ruby-value">80</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">remote_address</span> <span class="ruby-comment">#=&gt; #&lt;Addrinfo: 221.186.184.68:80 TCP&gt;</span>
}

<span class="ruby-constant">TCPServer</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;127.0.0.1&quot;</span>, <span class="ruby-value">1728</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">serv</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">c</span> = <span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;127.0.0.1&quot;</span>, <span class="ruby-value">1728</span>)
  <span class="ruby-identifier">s</span> = <span class="ruby-identifier">serv</span>.<span class="ruby-identifier">accept</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">remote_address</span> <span class="ruby-comment">#=&gt; #&lt;Addrinfo: 127.0.0.1:36504 TCP&gt;</span>
}
</pre>

                              <div class="method-source-code" id="remote_address-source">
            <pre>static VALUE
bsock_remote_address(VALUE sock)
{
    union_sockaddr buf;
    socklen_t len = (socklen_t)sizeof buf;
    socklen_t len0 = len;
    rb_io_t *fptr;

    GetOpenFile(sock, fptr);
    if (getpeername(fptr-&gt;fd, &amp;buf.addr, &amp;len) &lt; 0)
        rb_sys_fail(&quot;getpeername(2)&quot;);
    if (len0 &lt; len) len = len0;
    return rsock_fd_socket_addrinfo(fptr-&gt;fd, &amp;buf.addr, len);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-send" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          send(mesg, flags [, dest_sockaddr]) &rarr; numbytes_sent
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>send <em>mesg</em> via <em>basicsocket</em>.</p>

<p><em>mesg</em> should be a string.</p>

<p><em>flags</em> should be a bitwise OR of Socket::MSG_* constants.</p>

<p><em>dest_sockaddr</em> should be a packed sockaddr string or an addrinfo.</p>

<pre class="ruby"><span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&quot;localhost&quot;</span>, <span class="ruby-value">80</span>) {<span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span>
  <span class="ruby-identifier">s</span>.<span class="ruby-identifier">send</span> <span class="ruby-string">&quot;GET / HTTP/1.0\r\n\r\n&quot;</span>, <span class="ruby-value">0</span>
  <span class="ruby-identifier">p</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">read</span>
}
</pre>

                              <div class="method-source-code" id="send-source">
            <pre>VALUE
rsock_bsock_send(int argc, VALUE *argv, VALUE socket)
{
    struct rsock_send_arg arg;
    VALUE flags, to;
    rb_io_t *fptr;
    rb_blocking_function_t *func;
    const char *funcname;

    rb_scan_args(argc, argv, &quot;21&quot;, &amp;arg.mesg, &amp;flags, &amp;to);

    StringValue(arg.mesg);
    if (!NIL_P(to)) {
        SockAddrStringValue(to);
        to = rb_str_new4(to);
        arg.to = (struct sockaddr *)RSTRING_PTR(to);
        arg.tolen = RSTRING_SOCKLEN(to);
        func = rsock_sendto_blocking;
        funcname = &quot;sendto(2)&quot;;
    }
    else {
        func = rsock_send_blocking;
        funcname = &quot;send(2)&quot;;
    }

    RB_IO_POINTER(socket, fptr);

    arg.fd = fptr-&gt;fd;
    arg.flags = NUM2INT(flags);

    while (true) {
#ifdef RSOCK_WAIT_BEFORE_BLOCKING
        rb_io_wait(socket, RB_INT2NUM(RUBY_IO_WRITABLE), Qnil);
#endif

        ssize_t n = (ssize_t)BLOCKING_REGION_FD(func, &amp;arg);

        if (n &gt;= 0) return SSIZET2NUM(n);

        if (rb_io_maybe_wait_writable(errno, socket, RUBY_IO_TIMEOUT_DEFAULT)) {
            continue;
        }

        rb_sys_fail(funcname);
    }
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sendmsg" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          sendmsg(mesg, flags=0, dest_sockaddr=nil, *controls) &rarr; numbytes_sent
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>sendmsg sends a message using sendmsg(2) system call in blocking manner.</p>

<p><em>mesg</em> is a string to send.</p>

<p><em>flags</em> is bitwise OR of MSG_* constants such as Socket::MSG_OOB.</p>

<p><em>dest_sockaddr</em> is a destination socket address for connection-less socket. It should be a sockaddr such as a result of <a href="Socket.html#method-c-sockaddr_in"><code>Socket.sockaddr_in</code></a>. An <a href="Addrinfo.html"><code>Addrinfo</code></a> object can be used too.</p>

<p><em>controls</em> is a list of ancillary data. The element of <em>controls</em> should be <a href="Socket/AncillaryData.html"><code>Socket::AncillaryData</code></a> or 3-elements array. The 3-element array should contains cmsg_level, cmsg_type and data.</p>

<p>The return value, <em>numbytes_sent</em> is an integer which is the number of bytes sent.</p>

<p>sendmsg can be used to implement send_io as follows:</p>

<pre class="ruby"><span class="ruby-comment"># use Socket::AncillaryData.</span>
<span class="ruby-identifier">ancdata</span> = <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">AncillaryData</span>.<span class="ruby-identifier">int</span>(<span class="ruby-value">:UNIX</span>, <span class="ruby-value">:SOCKET</span>, <span class="ruby-value">:RIGHTS</span>, <span class="ruby-identifier">io</span>.<span class="ruby-identifier">fileno</span>)
<span class="ruby-identifier">sock</span>.<span class="ruby-identifier">sendmsg</span>(<span class="ruby-string">&quot;a&quot;</span>, <span class="ruby-value">0</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">ancdata</span>)

<span class="ruby-comment"># use 3-element array.</span>
<span class="ruby-identifier">ancdata</span> = [<span class="ruby-value">:SOCKET</span>, <span class="ruby-value">:RIGHTS</span>, [<span class="ruby-identifier">io</span>.<span class="ruby-identifier">fileno</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-string">&quot;i!&quot;</span>)]
<span class="ruby-identifier">sock</span>.<span class="ruby-identifier">sendmsg</span>(<span class="ruby-string">&quot;\0&quot;</span>, <span class="ruby-value">0</span>, <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">ancdata</span>)
</pre>

                              <div class="method-source-code" id="sendmsg-source">
            <pre><span class="ruby-comment"># File socket/lib/socket.rb, line 307</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sendmsg</span>(<span class="ruby-identifier">mesg</span>, <span class="ruby-identifier">flags</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">dest_sockaddr</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">controls</span>)
  <span class="ruby-identifier">__sendmsg</span>(<span class="ruby-identifier">mesg</span>, <span class="ruby-identifier">flags</span>, <span class="ruby-identifier">dest_sockaddr</span>, <span class="ruby-identifier">controls</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-sendmsg_nonblock" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          sendmsg_nonblock(mesg, flags=0, dest_sockaddr=nil, *controls, opts={}) &rarr; numbytes_sent
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="BasicSocket.html#method-i-sendmsg_nonblock"><code>sendmsg_nonblock</code></a> sends a message using sendmsg(2) system call in non-blocking manner.</p>

<p>It is similar to <a href="BasicSocket.html#method-i-sendmsg"><code>BasicSocket#sendmsg</code></a> but the non-blocking flag is set before the system call and it doesn’t retry the system call.</p>

<p>By specifying a keyword argument <em>exception</em> to <code>false</code>, you can indicate that <a href="BasicSocket.html#method-i-sendmsg_nonblock"><code>sendmsg_nonblock</code></a> should not raise an IO::WaitWritable exception, but return the symbol <code>:wait_writable</code> instead.</p>

                              <div class="method-source-code" id="sendmsg_nonblock-source">
            <pre><span class="ruby-comment"># File socket/lib/socket.rb, line 323</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">sendmsg_nonblock</span>(<span class="ruby-identifier">mesg</span>, <span class="ruby-identifier">flags</span> = <span class="ruby-value">0</span>, <span class="ruby-identifier">dest_sockaddr</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">controls</span>,
                     <span class="ruby-value">exception:</span> <span class="ruby-keyword">true</span>)
  <span class="ruby-identifier">__sendmsg_nonblock</span>(<span class="ruby-identifier">mesg</span>, <span class="ruby-identifier">flags</span>, <span class="ruby-identifier">dest_sockaddr</span>, <span class="ruby-identifier">controls</span>, <span class="ruby-identifier">exception</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-setsockopt" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          setsockopt(level, optname, optval)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          setsockopt(socketoption)
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Sets a socket option. These are protocol and system specific, see your local system documentation for details.</p>

<h3 id="method-i-setsockopt-label-Parameters">Parameters<span><a href="#method-i-setsockopt-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><code>level</code> is an integer, usually one of the SOL_ constants such as Socket::SOL_SOCKET, or a protocol level. A string or symbol of the name, possibly without prefix, is also accepted.</p>
</li><li>
<p><code>optname</code> is an integer, usually one of the SO_ constants, such as Socket::SO_REUSEADDR. A string or symbol of the name, possibly without prefix, is also accepted.</p>
</li><li>
<p><code>optval</code> is the value of the option, it is passed to the underlying setsockopt() as a pointer to a certain number of bytes. How this is done depends on the type:</p>
<ul><li>
<p>Integer: value is assigned to an int, and a pointer to the int is passed, with length of sizeof(int).</p>
</li><li>
<p>true or false: 1 or 0 (respectively) is assigned to an int, and the int is passed as for an Integer. Note that <code>false</code> must be passed, not <code>nil</code>.</p>
</li><li>
<p>String: the string’s data and length is passed to the socket.</p>
</li></ul>
</li><li>
<p><code>socketoption</code> is an instance of <a href="Socket/Option.html"><code>Socket::Option</code></a></p>
</li></ul>

<h3 id="method-i-setsockopt-label-Examples">Examples<span><a href="#method-i-setsockopt-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Some socket options are integers with boolean values, in this case <a href="BasicSocket.html#method-i-setsockopt"><code>setsockopt</code></a> could be called like this:</p>

<pre class="ruby"><span class="ruby-identifier">sock</span>.<span class="ruby-identifier">setsockopt</span>(<span class="ruby-value">:SOCKET</span>, <span class="ruby-value">:REUSEADDR</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">sock</span>.<span class="ruby-identifier">setsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">SOL_SOCKET</span>,<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">SO_REUSEADDR</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">sock</span>.<span class="ruby-identifier">setsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">Option</span>.<span class="ruby-identifier">bool</span>(<span class="ruby-value">:INET</span>, <span class="ruby-value">:SOCKET</span>, <span class="ruby-value">:REUSEADDR</span>, <span class="ruby-keyword">true</span>))
</pre>

<p>Some socket options are integers with numeric values, in this case <a href="BasicSocket.html#method-i-setsockopt"><code>setsockopt</code></a> could be called like this:</p>

<pre class="ruby"><span class="ruby-identifier">sock</span>.<span class="ruby-identifier">setsockopt</span>(<span class="ruby-value">:IP</span>, <span class="ruby-value">:TTL</span>, <span class="ruby-value">255</span>)
<span class="ruby-identifier">sock</span>.<span class="ruby-identifier">setsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">IPPROTO_IP</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">IP_TTL</span>, <span class="ruby-value">255</span>)
<span class="ruby-identifier">sock</span>.<span class="ruby-identifier">setsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">Option</span>.<span class="ruby-identifier">int</span>(<span class="ruby-value">:INET</span>, <span class="ruby-value">:IP</span>, <span class="ruby-value">:TTL</span>, <span class="ruby-value">255</span>))
</pre>

<p>Option values may be structs. Passing them can be complex as it involves examining your system headers to determine the correct definition. An example is an <code>ip_mreq</code>, which may be defined in your system headers as:</p>

<pre class="ruby"><span class="ruby-identifier">struct</span> <span class="ruby-identifier">ip_mreq</span> {
  <span class="ruby-identifier">struct</span>  <span class="ruby-identifier">in_addr</span> <span class="ruby-identifier">imr_multiaddr</span>;
  <span class="ruby-identifier">struct</span>  <span class="ruby-identifier">in_addr</span> <span class="ruby-identifier">imr_interface</span>;
};
</pre>

<p>In this case <a href="BasicSocket.html#method-i-setsockopt"><code>setsockopt</code></a> could be called like this:</p>

<pre class="ruby"><span class="ruby-identifier">optval</span> = <span class="ruby-constant">IPAddr</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;224.0.0.251&quot;</span>).<span class="ruby-identifier">hton</span> <span class="ruby-operator">+</span>
         <span class="ruby-constant">IPAddr</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">INADDR_ANY</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">AF_INET</span>).<span class="ruby-identifier">hton</span>
<span class="ruby-identifier">sock</span>.<span class="ruby-identifier">setsockopt</span>(<span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">IPPROTO_IP</span>, <span class="ruby-constant">Socket</span><span class="ruby-operator">::</span><span class="ruby-constant">IP_ADD_MEMBERSHIP</span>, <span class="ruby-identifier">optval</span>)
</pre>

                              <div class="method-source-code" id="setsockopt-source">
            <pre>static VALUE
bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
{
    VALUE lev, optname, val;
    int family, level, option;
    rb_io_t *fptr;
    int i;
    char *v;
    int vlen;

    if (argc == 1) {
        lev = rb_funcall(argv[0], rb_intern(&quot;level&quot;), 0);
        optname = rb_funcall(argv[0], rb_intern(&quot;optname&quot;), 0);
        val = rb_funcall(argv[0], rb_intern(&quot;data&quot;), 0);
    }
    else {
        rb_scan_args(argc, argv, &quot;30&quot;, &amp;lev, &amp;optname, &amp;val);
    }

    GetOpenFile(sock, fptr);
    family = rsock_getfamily(fptr);
    level = rsock_level_arg(family, lev);
    option = rsock_optname_arg(family, level, optname);

    switch (TYPE(val)) {
      case T_FIXNUM:
        i = FIX2INT(val);
        goto numval;
      case T_FALSE:
        i = 0;
        goto numval;
      case T_TRUE:
        i = 1;
      numval:
        v = (char*)&amp;i; vlen = (int)sizeof(i);
        break;
      default:
        StringValue(val);
        v = RSTRING_PTR(val);
        vlen = RSTRING_SOCKLEN(val);
        break;
    }

    rb_io_check_closed(fptr);
    if (setsockopt(fptr-&gt;fd, level, option, v, vlen) &lt; 0)
        rsock_sys_fail_path(&quot;setsockopt(2)&quot;, fptr-&gt;pathv);

    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-shutdown" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          shutdown([how]) &rarr; 0
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Calls shutdown(2) system call.</p>

<p>s.shutdown(Socket::SHUT_RD) disallows further read.</p>

<p>s.shutdown(Socket::SHUT_WR) disallows further write.</p>

<p>s.shutdown(Socket::SHUT_RDWR) disallows further read and write.</p>

<p><em>how</em> can be symbol or string:</p>
<ul><li>
<p>:RD, :SHUT_RD, “RD” and “SHUT_RD” are accepted as Socket::SHUT_RD.</p>
</li><li>
<p>:WR, :SHUT_WR, “WR” and “SHUT_WR” are accepted as Socket::SHUT_WR.</p>
</li><li>
<p>:RDWR, :SHUT_RDWR, “RDWR” and “SHUT_RDWR” are accepted as Socket::SHUT_RDWR.</p>

<p><a href="UNIXSocket.html#method-c-pair"><code>UNIXSocket.pair</code></a> {|s1, s2|</p>

<pre class="ruby"><span class="ruby-identifier">s1</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;ping&quot;</span>
<span class="ruby-identifier">s1</span>.<span class="ruby-identifier">shutdown</span>(<span class="ruby-value">:WR</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s2</span>.<span class="ruby-identifier">read</span>          <span class="ruby-comment">#=&gt; &quot;ping\n&quot;</span>
<span class="ruby-identifier">s2</span>.<span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;pong&quot;</span>
<span class="ruby-identifier">s2</span>.<span class="ruby-identifier">close</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">s1</span>.<span class="ruby-identifier">read</span>          <span class="ruby-comment">#=&gt; &quot;pong\n&quot;</span>
</pre>

<p>}</p>
</li></ul>

                              <div class="method-source-code" id="shutdown-source">
            <pre>static VALUE
bsock_shutdown(int argc, VALUE *argv, VALUE sock)
{
    VALUE howto;
    int how;
    rb_io_t *fptr;

    rb_scan_args(argc, argv, &quot;01&quot;, &amp;howto);
    if (howto == Qnil)
        how = SHUT_RDWR;
    else {
        how = rsock_shutdown_how_arg(howto);
        if (how != SHUT_WR &amp;&amp; how != SHUT_RD &amp;&amp; how != SHUT_RDWR) {
            rb_raise(rb_eArgError, &quot;`how&#39; should be either :SHUT_RD, :SHUT_WR, :SHUT_RDWR&quot;);
        }
    }
    GetOpenFile(sock, fptr);
    if (shutdown(fptr-&gt;fd, how) == -1)
        rb_sys_fail(&quot;shutdown(2)&quot;);

    return INT2FIX(0);
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

